package com.cn.lycss.servlet.user;

import com.alibaba.fastjson.JSONObject;
import com.cn.lycss.model.ResultModel;
import com.cn.lycss.model.UserModel;
import com.cn.lycss.service.UserService;
import com.cn.lycss.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/user/findById")
public class UserFindById extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      req.setCharacterEncoding("utf-8");
      resp.setCharacterEncoding("utf-8");
        String id=req.getParameter("id");
        UserModel userModel=new UserModel();
        userModel.setId(Integer.parseInt(id));
        //        3.创建服务逻辑层
        UserService userService = new UserServiceImpl();
        //        4.接收服务逻辑层返回信息

            ResultModel resultModel = userService.findById(userModel);
        //        5.将信息返回给前端
        resp.getWriter().println(JSONObject.toJSONString(resultModel));
    }
}
